﻿(function (winjs, mvvmStack, applicationController, target, services) {
    "use strict";

    var ViewModelLocator = winjs.Class.derive(mvvmStack.ViewModelLocatorBase, function (target) {
        this.target = target;
    },
        {
            createViewModelForUrl: function (uri) {
                switch (uri) {
                    case target.home:
                        this.viewModels.homeViewModel = this.viewModels.homeViewModel || new Demo.ViewModels.HomeViewModel(applicationController);
                        break;
                    case target.section:
                        this.viewModels.sectionViewModel = new Demo.ViewModels.SectionViewModel(applicationController, services.imageService);
                        this.viewModels.sectionViewModel.load();
                        break;
                }
            },
            createDesignTimeViewModels: function () {
                //Fake section viewModel for design time support
                var SectionViewModel = winjs.Class.define(function () {
                    this.sectionTitle = "Sezione 0";
                    var images = [{ uri: "/images/mtb.jpg", title: 'This is the title' }];
                    this.images = new winjs.Binding.List(images);
                    this.currentPage = winjs.Binding.as({
                        value: 0
                    });
                },
                    {
                        currentPage: null,
                        images: null,
                    });


                this.viewModels.sectionViewModel = new SectionViewModel();
            }
        });

    var viewModelLocator = new ViewModelLocator(target);
    
    //Uncomment this to create a fake design time viewmodel to use with the page associated with default.html's page navigator
    //viewModelLocator.createDesignTimeViewModels();

    //Creates viewmodel associated with home page
    viewModelLocator.createViewModelForUrl(target.home);


    winjs.Namespace.define("Demo", {
        ViewModelLocator: viewModelLocator
    });


})(WinJS, MvvmStack, Demo.Application.ApplicationController, Demo.Navigation.target, Demo.Services)